package com.fr.europeanchampions;

import org.junit.Test;

/**
*作者：furong
*日期：2016年12月8日
*时间：下午3:19:40
*/
public class EuropeanChampions {
	//16-17
//    private final String[] groupA = { "阿森纳", "那不勒斯", "巴塞罗那", "马德里竞技", "摩纳哥", "多特蒙德", "莱斯特", "尤文图斯" };
//    private final String[] groupB = { "巴黎圣日耳曼", "本菲卡", "曼城", "拜仁慕尼黑", "勒沃库森", "皇家马德里", "波尔图", "塞维利亚" };
    //17-18
	//小组第一：曼联、巴黎圣日耳曼、罗马、巴塞罗那、利物浦、曼城、贝西克塔斯、热刺
	//小组第二：巴塞尔、拜仁慕尼黑、切尔西、尤文图斯、塞维利亚、顿涅茨克矿工、波尔图、皇马
	private final String[] groupA = { "曼联","巴黎圣日耳曼","罗马","巴塞罗那","利物浦","曼城","贝西克塔斯","热刺" };
	private final String[] groupB = { "巴塞尔","拜仁慕尼黑","切尔西","尤文图斯","塞维利亚","顿涅茨克矿工","波尔图","皇马" };

	// 1西班牙 2德国 3英格兰 4意大利 5法国 6葡萄牙 7土耳其 8乌克兰 9瑞士 
    private final int[] groupACountry = { 3, 5, 4, 1, 3, 3, 7, 3 };
    private final int[] groupBCountry = { 9, 2, 3, 4, 1, 8, 6, 1 };

    private int[] opponent = { -1, -1, -1, -1, -1, -1, -1, -1 };
    private int sum = 0;

    @Test
    public void calculation() {
        ergodic(0);
    }

    private void ergodic(int i) {
        if (i > 7) {
            show();
        } else {
            for (int j = 0; j <= 7; j++) {
                // 原则 不同国，不同小组， 没匹配到过
                if (groupACountry[i] != groupBCountry[j] && i != j && !contain(j)) {
                    opponent[i] = j;
                    ergodic(i + 1);
                    opponent[i] = -1;
                }
            }
        }
    }

    private boolean contain(int j) {
        for (int a : opponent) {
            if (a == j) {
                return true;
            }
        }
        return false;
    }

    private void show() {

        if (opponent[3] == 2 && opponent[2] == 7 && opponent[6] == 5) {
            ++sum;
            System.out.println("第" + (sum) + "组对阵形式：");
            for (int i = 0; i <= 7; i++) {
                System.out.println(groupA[i] + " VS " + groupB[opponent[i]] + "");
            }
            System.out.println("======================");
        }

    }
}
